package sit.engreal.leetcode.problems200;

/**
 * <a href="https://leetcode.cn/problems/number-of-1-bits/">191. 位1的个数</a>
 */
public class LeetCode191 {
    public int hammingWeight(int n) {
        int m = 0;
        while (n != 0) {
            if ((n & 1) == 1) {
                m++;
            }
            n = n >>> 1;
        }
        return m;
    }

    public static void main(String[] args) {
        final LeetCode191 demo = new LeetCode191();

        System.out.println(demo.hammingWeight(Integer.MAX_VALUE));
        System.out.println(demo.hammingWeight(Integer.MIN_VALUE));
        System.out.println(demo.hammingWeight(-1));
    }
}
